package com.example.anql.service.impl;

import com.example.anql.common.ReturnObject;
import com.example.anql.common.ReturnUtil;
import com.example.anql.entity.ShopMassage;
import com.example.anql.dao.ShopMassageDao;
import com.example.anql.service.ShopMassageService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * (ShopMassage)表服务实现类
 *
 * @author makejava
 * @since 2022-12-12 10:39:59
 */
@Service("shopMassageService")
public class ShopMassageServiceImpl implements ShopMassageService {
    @Resource
    private ShopMassageDao shopMassageDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ShopMassage queryById(Integer id) {
        return this.shopMassageDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param shopMassage 筛选条件
     * @return 查询结果
     */
    @Override
    public ReturnObject queryByPage(ShopMassage shopMassage ) {
        PageHelper.startPage(shopMassage.getPage(),shopMassage.getSize());
        List<ShopMassage> listShop = shopMassageDao.queryByPage(shopMassage);
        PageInfo<ShopMassage> pageInfo = new PageInfo<>(listShop);

        return ReturnUtil.success(pageInfo);
    }

    /**
     * 新增数据
     *
     * @param shopMassage 实例对象
     * @return 实例对象
     */
    @Override
    public ShopMassage insert(ShopMassage shopMassage) {
        this.shopMassageDao.insert(shopMassage);
        return shopMassage;
    }

    /**
     * 修改数据
     *
     * @param shopMassage 实例对象
     * @return 实例对象
     */
    @Override
    public ShopMassage update(ShopMassage shopMassage) {
        this.shopMassageDao.update(shopMassage);
        return this.queryById(shopMassage.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.shopMassageDao.deleteById(id) > 0;
    }
}
